package com.fjh.springboot_01.service.impl;

import com.fjh.springboot_01.mapper.TeacherInfoMapper;
import com.fjh.springboot_01.pojo.TeacherInfo;
import com.fjh.springboot_01.service.TeacherInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class TeacherInfoServiceImpl implements TeacherInfoService {
    @Autowired
    private TeacherInfoMapper teacherInfoMapper;

    @Override
    public void submitTeacherInfo(TeacherInfo teacherInfo) {
        teacherInfoMapper.insert(teacherInfo);
    }

    @Override
    public TeacherInfo getTeacherInfo(Integer userId) {
        List<TeacherInfo> teacherInfoList = teacherInfoMapper.findByUserId(userId);
        // 如果列表为空，返回null；否则返回第一条记录
        return teacherInfoList != null && !teacherInfoList.isEmpty() ? teacherInfoList.get(0) : null;
    }

    @Override
    public List<TeacherInfo> getAllTeacherInfo() {
        return teacherInfoMapper.findAll();
    }

    @Override
    public void updateTeacherInfo(TeacherInfo teacherInfo) {
        teacherInfoMapper.update(teacherInfo);
    }

    @Override
    public void deleteTeacherInfo(Integer userId) {
        teacherInfoMapper.deleteByUserId(userId);
    }
} 